home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / utility / nonag.zip / NONAG.C next >
C/C++ Source or Header  |  1990-05-30  |  2KB  |  58 lines

  1. /* program to mark windows executables so win3 does not nag about
  2.  * compatibility.  does not solve problems of compatibility, however.
  3.  */
  4. #define LINT_ARGS
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. /*----------------------------------------------- prototypes ---------------*/
  9. int main( int ac, char *av[] );
  10.  
  11. /*----------------------------------------------- main ---------------------*/
  12. int main( int ac, char *av[] )
  13. {
  14.     FILE *ioExe;
  15.     int uBuffer[0x21C], uIndex;
  16.  
  17.     if (ac != 2) {
  18.     fprintf( stderr,
  19.          "usage is\n\tnonag <windows .exe file with extension>\n" );
  20.     exit( 1 );
  21.     }
  22.     else if (!(ioExe = fopen( av[1], "r+b" ))) {
  23.     perror( av[1] );
  24.     exit( 1 );
  25.     }
  26.     if (fread( uBuffer, 0x9F, 1, ioExe ) != 1) {
  27.     fprintf( stderr, "Can't read header from %s\n", av[1] );
  28.     exit( 1 );
  29.     }
  30.     if (uBuffer[0] != 0x5A4D) {
  31.     fprintf( stderr, "File %s format not as expected; file not marked.\n", av[1] );
  32.     exit( 1 );
  33.     }
  34.     uIndex = uBuffer[0x1E];
  35.     if (fseek( ioExe, (unsigned long)uIndex, SEEK_SET )) {
  36.     fprintf( stderr, "Can't seek on file %s to read new .exe header\n", av[1] );
  37.     exit( 1 );
  38.     }
  39.     if (fread( uBuffer, 0x1C * sizeof( uBuffer[0] ), 1, ioExe ) != 1) {
  40.     fprintf( stderr, "Can't read new .exe header from %s\n", av[1] );
  41.     exit( 1 );
  42.     }
  43.     if (uBuffer[0] != 0x454E || uBuffer[0x1B] != 0x0002) {
  44.     fprintf( stderr, "File %s format not as expected; file not marked.\n", av[1] );
  45.     exit( 1 );
  46.     }
  47.     uBuffer[0x1B] = 0x0402;
  48.     if (fseek( ioExe, (unsigned long)uIndex, SEEK_SET )) {
  49.     fprintf( stderr, "Can't seek on file %s for re-write\n", av[1] );
  50.     exit( 1 );
  51.     }
  52.     else if (fwrite( uBuffer, 0x1C * sizeof( uBuffer[0] ), 1, ioExe ) != 1) {
  53.     fprintf( stderr, "Re-write to %s failed.\n", av[1] );
  54.     exit( 1 );
  55.     }
  56.     return( 0 );
  57. }
  58.